home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <conio.h>
- #include <dos.h>
- #define BIOS_VIDEO 0x10
- void interrupt vio_handler(void);
- void interrupt (*old_handler)(void);
- void chain_int(void interrupt (*p_func)());
- main()
- {
- union REGS xr, yr;
- int c;
- /* Install kthe new handler named vio_handler
- * Disable interrupts when changing handler */
- disable();
- old_handler =getvect(BIOS_VIDEO);
- setvect(BIOS_VIDEO,vio_handler);
- enable();
- /* Print out address of old handler using %p format */
- printf("\nThe address of the old handler is: "
- "%Fp\n", old_handler);
- printf("Installed new handler: %Fp\n", vio_handler);
-
- /* Do some video I/O --change cursor to a solid block */
- xr.h.ah =1;
- xr.h.ch =0;
- xr.h.cl =8;
- int86(BIOS_VIDEO, &xr, &yr);
- /* Quit when user says so */
- printf("Hit q to quit: ");
- while( (c = getch() ) != 'q'); /* Keep looping till 'q' */
- /* Reset vector. Disable interrupts when doing this */
- disable();
- setvect(BIOS_VIDEO, old_handler);
- enable();
- }
- /* ----------------------------------------------------------- */
- void interrupt vio_handler(void)
- {
- /* Our handler simply chains to the old_handler using
- * chain_int (see below) */
- chain_int(old_handler);
- }
- /* ------------------------------------------------------------ */
- void chain_int(void(interrupt *p_func)())
- {
- /* Embed machine code to properly call an interrupt
- * handler by using the library routine __emit__.
- * Note that Turbo C would have generated
- * correct code (push flags, then call handler) even
- * if we had invoked the old handler with the usual
- * (*old_handler)(),but we wanted to show how
- * __emit__works.
- */
- /* PUSHF */
- __emit__((unsigned char)0x9c);
- /* CALL FAR [BP+4] */
- __emit__((unsigned char)0xff, 0x5e, &p_func);
- }